package com.leftcode.test;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class LeftCodeMain extends Activity {
	private float mPreviousX;
	private float mPreviousY;
	private GLSurfaceView view;
	private LeftCodeRenderer renderer;
	private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /* 设置窗体为全屏模式，无标题 */
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
 
        /* 创建一个 GLSurfaceView 用于绘制表面 */
         view = new GLSurfaceView(this);
         renderer =  new LeftCodeRenderer(this);
 
        /* 设置 Renderer 用于执行实际的绘制工作 */
        view.setRenderer(renderer);
 
        /* 设置绘制模式为 持续绘制  */
        view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
 
        /* 将创建好的 GLSurfaceView 设置为当前 Activity 的内容视图 */
        setContentView(view);
        

    }
    
	   public boolean onTouchEvent(MotionEvent event)
	    {
	    	float x = event.getX();
	    	float y = event.getY();
	    	switch (event.getAction())
	    	{
	    	case MotionEvent.ACTION_MOVE:
	    		float dx = x- mPreviousX;
	    		float dy = y - mPreviousY;
	    		renderer.xrot += dx*TOUCH_SCALE_FACTOR;
	    		renderer.yrot += dy*TOUCH_SCALE_FACTOR;
	    	}
	    	mPreviousX = x;
	    	mPreviousY = y;
	    	return true;
	    }
}